package com.ktgj.customer.service.impl;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.ktgj.common.core.constant.CustomerConstants;
import com.ktgj.common.core.constant.FlightOrderConstants;
import com.ktgj.common.core.domain.R;
import com.ktgj.common.core.enums.EmHelper;
import com.ktgj.common.core.utils.ExcelUtils;
import com.ktgj.common.core.utils.HttpClientUtil;
import com.ktgj.common.core.utils.helper.StringHelper;
import com.ktgj.customer.domain.Employee;
import com.ktgj.customer.domain.FinanceAutobillException;
import com.ktgj.customer.domain.vo.BillDetailsVo;
import com.ktgj.customer.domain.vo.CountVo;
import com.ktgj.customer.domain.vo.UpLoadFileVo;
import com.ktgj.customer.mapper.FinanceAutobillExceptionMapper;
import com.ktgj.customer.service.IEmployeeService;
import com.ktgj.customer.service.ILoginService;
import com.ktgj.flight.api.RemoteFlightService;
import com.ktgj.flight.api.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.mapper.FinanceAutobillRecordMapper;
import com.ktgj.customer.domain.FinanceAutobillRecord;
import com.ktgj.customer.service.IFinanceAutobillRecordService;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;

/**
 * 财务自动对账文件记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-13
 */
@Service
public class FinanceAutobillRecordServiceImpl implements IFinanceAutobillRecordService 
{
    @Autowired
    private FinanceAutobillRecordMapper financeAutobillRecordMapper;

    @Autowired
    private IEmployeeService employeeService;

    @Autowired
    private ILoginService loginService;

    @Autowired
    private RemoteFlightService remoteFlightService;

    @Autowired
    private FinanceAutobillExceptionMapper financeAutobillExceptionMapper;
//
//    @Autowired
//    private HttpClientUtil httpClientUtil;

    /**
     * 查询财务自动对账文件记录
     * 
     * @param billRecordId 财务自动对账文件记录ID
     * @return 财务自动对账文件记录
     */
    @Override
    public FinanceAutobillRecord selectFinanceAutobillRecordById(Long billRecordId)
    {
        return financeAutobillRecordMapper.selectFinanceAutobillRecordById(billRecordId);
    }

    /**
     * 查询财务自动对账文件记录列表
     * 
     * @param financeAutobillRecord 财务自动对账文件记录
     * @return 财务自动对账文件记录
     */
    @Override
    public List<FinanceAutobillRecord> selectFinanceAutobillRecordList(FinanceAutobillRecord financeAutobillRecord)
    {
        return financeAutobillRecordMapper.selectFinanceAutobillRecordList(financeAutobillRecord);
    }

    /**
     * 新增财务自动对账文件记录
     * 
     * @param financeAutobillRecord 财务自动对账文件记录
     * @return 结果
     */
    @Override
    public int insertFinanceAutobillRecord(HttpServletRequest request, FinanceAutobillRecord financeAutobillRecord) throws Exception {
        SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd");
        String token = request.getHeader("token");
        Employee loginEmployeeByToken = loginService.getLoginEmployeeByToken(token);
        if (loginEmployeeByToken != null){
            financeAutobillRecord.setEmployeeId(loginEmployeeByToken.getEmployeeId());
        }
        else {
            throw new Exception("登录已过期");
        }
        Date date = new Date();


        for (String billBeLong : financeAutobillRecord.getBillBelongList()) {
            financeAutobillRecord.setBillBelong(billBeLong);
            financeAutobillRecord.setCreateTime(date);
            String bill;
            if (financeAutobillRecord.getExceltype().equals(FlightOrderConstants.Airline.getValue())){
                bill = billBeLong.substring(0, billBeLong.length() - 2);
            }
            else {
                bill = billBeLong;
            }
            for (UpLoadFileVo upLodeVo : financeAutobillRecord.getUploadList()) {
                if (upLodeVo.getOldName().indexOf(bill) != -1){
                    String[] urls = StrUtil.splitToArray(upLodeVo.getUrl(), '/');
                    String newName = urls[urls.length - 1];
                    financeAutobillRecord.setNewName(newName);

                    String oldName = upLodeVo.getOldName();
                    financeAutobillRecord.setOldName(oldName);

                    break;
                }
            }
            if (billBeLong.equals("航协出票"))
            {
                for (UpLoadFileVo uploadFile : financeAutobillRecord.getUploadList())
                {
                    String[] urls = StrUtil.splitToArray(uploadFile.getUrl(), '/');
                    String newName = urls[urls.length - 1];
                    financeAutobillRecord.setNewName(newName);
                    String oldName = uploadFile.getOldName();
                    financeAutobillRecord.setOldName(oldName);
                }
            }
            financeAutobillRecord.setOperationTime(date);
            try {
                financeAutobillRecord.setBillStartDate(time.parse(financeAutobillRecord.getBillStartTime()));
                financeAutobillRecord.setBillEndDate(time.parse(financeAutobillRecord.getBillEndTime()));
            } catch (Exception e){
                throw new Exception("时间转换错误");
            }
            String start = financeAutobillRecord.getBillStartTime().replace("-", "").replace(" ", "").replace(":", "");
            String end = financeAutobillRecord.getBillEndTime().replace("-", "").replace(" ", "").replace(":", "");
            financeAutobillRecord.setBillTimeNumber(start + "-" + end);
            int i = financeAutobillRecordMapper.insertFinanceAutobillRecord(financeAutobillRecord);
            if (i <= 0){
                throw new Exception("添加失败" + billBeLong);
            }
        }

        return 1;
    }

    /**
     * 修改财务自动对账文件记录
     * 
     * @param financeAutobillRecord 财务自动对账文件记录
     * @return 结果
     */
    @Override
    public int updateFinanceAutobillRecord(FinanceAutobillRecord financeAutobillRecord)
    {
        return financeAutobillRecordMapper.updateFinanceAutobillRecord(financeAutobillRecord);
    }

    /**
     * 批量删除财务自动对账文件记录
     * 
     * @param billRecordIds 需要删除的财务自动对账文件记录ID
     * @return 结果
     */
    @Override
    public int deleteFinanceAutobillRecordByIds(Long[] billRecordIds)
    {
        return financeAutobillRecordMapper.deleteFinanceAutobillRecordByIds(billRecordIds);
    }

    /**
     * 删除财务自动对账文件记录信息
     * 
     * @param billRecordId 财务自动对账文件记录ID
     * @return 结果
     */
    @Override
    public int deleteFinanceAutobillRecordById(Long billRecordId)
    {
        return financeAutobillRecordMapper.deleteFinanceAutobillRecordById(billRecordId);
    }

    /**
     * 原始账单查询
     * */
    @Override
    public List<FinanceAutobillRecord> billingInquiry(FinanceAutobillRecord financeAutobillRecord) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<FinanceAutobillRecord> financeAutobillRecordList = financeAutobillRecordMapper.billingInquiry(financeAutobillRecord);
        if (financeAutobillRecordList.size() > 0){
            for (FinanceAutobillRecord autobillRecord : financeAutobillRecordList) {
                if (autobillRecord.getReportType() != null && autobillRecord.getReportType().equals(FlightOrderConstants.Sales.getValue())){
                    autobillRecord.setReportType("销售");
                }
                else if (autobillRecord.getReportType() != null && autobillRecord.getReportType().equals(FlightOrderConstants.Refund.getValue())){
                    autobillRecord.setReportType("退票");
                }
                else if (autobillRecord.getReportType() != null && autobillRecord.getReportType().equals(FlightOrderConstants.SalesAndRefunds.getValue())){
                    autobillRecord.setReportType("销售和退票");
                }

                if (autobillRecord.getBillStartDate() != null){
                    autobillRecord.setBillStartTime(format.format(autobillRecord.getBillStartDate()));
                }
                if (autobillRecord.getBillEndDate() != null){
                    autobillRecord.setBillEndTime(format.format(autobillRecord.getBillEndDate()));
                }
                if (autobillRecord.getBillState() != null && autobillRecord.getBillState().equals(FlightOrderConstants.Initialization.getValue())){
                    autobillRecord.setBillState("初始化");
                }
                else  if (autobillRecord.getBillState() != null && autobillRecord.getBillState().equals(FlightOrderConstants.Generate.getValue())){
                    autobillRecord.setBillState("已生成账单");
                }
                else  if (autobillRecord.getBillState() != null && autobillRecord.getBillState().equals(FlightOrderConstants.Lapsed.getValue())){
                    autobillRecord.setBillState("失效账单");
                }

                if (autobillRecord.getEmployeeId() != null && autobillRecord.getEmployeeId() != 0){
                    Employee employee = employeeService.selectEmployeeById(autobillRecord.getEmployeeId());
                    if (employee != null){
                        autobillRecord.setEmployeeName(employee.getEmployeeName());
                    }
                }

                if (autobillRecord.getCreateTime() != null){
                    autobillRecord.setCreateDate(date.format(autobillRecord.getCreateTime()));
                }
            }
        }
        return financeAutobillRecordList;
    }

    /**
     * 原始账单详细
     * */
    @Override
    public List<BillDetailsVo> billDetails(Long id) {
        List<BillDetailsVo> billDetailsVoList = new ArrayList<>();
        FinanceAutobillRecord financeAutobillRecord = financeAutobillRecordMapper.billDetails(id);
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = format.format(financeAutobillRecord.getCreateTime());
//        String downFilePath = "C:\\Users\\a1874\\Desktop\\" + financeAutobillRecord.getOldName();
        String downFilePath = "D:\\ktgj\\reconciliation\\" + financeAutobillRecord.getNewName();
        String fileUrl = "http://172.16.7.51:9000/download/reconciliation/upload/" + date + "/" + financeAutobillRecord.getNewName();

        try {
            httpClientUtil.downloadNetworkFile(fileUrl, downFilePath);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            List<String> lstColumns = new ArrayList<>();
            lstColumns.add("票号");//账单记录号
            lstColumns.add("支付银行");//支付类型
            lstColumns.add("退票状态");//状态
            lstColumns.add("订单编号");//出票方订单号
            lstColumns.add("票面金额");//单张票面价
            lstColumns.add("代理费");//手续费
            lstColumns.add("实际支付金额");//单张票结算价格
            lstColumns.add("燃油");//燃油
            lstColumns.add("机建");//基建
            lstColumns.add("出票日期");//出票时间
            lstColumns.add("备注");//状态
            lstColumns.add("票面金额(不含税)");//单张票面价
            lstColumns.add("实际支付金额(含税)");//单张票结算价格
            lstColumns.add("终止票号");//账单记录号
            lstColumns.add("出票时间");//出票时间
            lstColumns.add("订单状态");//状态
            lstColumns.add("订单号");//出票方订单号
            lstColumns.add("实际支付");//单张票结算价格
            lstColumns.add("交易日期");//出票时间1
            lstColumns.add("交易时间");//出票时间2
            lstColumns.add("收入");//单张票结算价格
            lstColumns.add("支出");//单张票结算价格
            lstColumns.add("手续费");//手续费
            lstColumns.add("电子客票票号");//账单记录号
            lstColumns.add("退票单号");//出票方订单号
            lstColumns.add("票面价票面价差");//单张票面价
            lstColumns.add("结算价");//单张票结算价格
            lstColumns.add("燃油费");//燃油
            lstColumns.add("调账状态");//状态
            lstColumns.add("子订单号/订单号");//出票方订单号
            lstColumns.add("定额手续费");//手续费
            lstColumns.add("票面价");//单张票面价
            lstColumns.add("民航基金");//基建
            lstColumns.add("实付金额");//单张票结算价格
            lstColumns.add("订单类型");//状态
            lstColumns.add("票价总额");//单张票结算价格
            lstColumns.add("商户订单号");//出票方订单号
            lstColumns.add("支付时间");//出票时间
            lstColumns.add("支付金额");//单张票结算价格
            lstColumns.add("AIR");//账单记录号1
            lstColumns.add("Document Number");//账单记录号2
            lstColumns.add("Balance Payable");//金额
            List<Map<String, String>> lstRowData = ExcelUtils.readExcelWithColumn(downFilePath, lstColumns);

            String air = null;
            String fuel = null;
            String tmpDate = null;
            String time = null;
            String infrastructure = null;
            BillDetailsVo billDetailsVo = new BillDetailsVo();
            for (Map<String, String> lstRowDatum : lstRowData) {
                int count = 1;
                for (Map.Entry<String, String> stringStringEntry : lstRowDatum.entrySet()) {
                        if (stringStringEntry.getKey().equals("AIR")){
                        air = stringStringEntry.getValue();
                    }

                    //获取账单记录号
                    if (stringStringEntry.getKey().indexOf("票号") != -1 ||
                            stringStringEntry.getKey().indexOf("终止票号") != -1 ||
                            stringStringEntry.getKey().indexOf("电子客票票号") != -1 ||
                            stringStringEntry.getKey().indexOf("Document Number") != -1){
                        if (air != null){
                            air = air + "-" + stringStringEntry.getValue();
                        }
                        else {
                            air = stringStringEntry.getValue();
                        }
                        billDetailsVo.setRecordNum(air);
                    }

                    //获取账单渠道+支付类型
                    if (stringStringEntry.getKey().indexOf("支付银行") != -1){
                        billDetailsVo.setChannelType(financeAutobillRecord.getBillBelong() + "-" + stringStringEntry.getValue());
                    }

                    //获取状态
                    if (stringStringEntry.getKey().indexOf("退票状态") != -1 ||
                            stringStringEntry.getKey().indexOf("备注") != -1 ||
                            stringStringEntry.getKey().indexOf("订单状态") != -1 ||
                            stringStringEntry.getKey().indexOf("订单类型") != -1){
                        billDetailsVo.setStart(stringStringEntry.getValue());
                    }

                    //获取出票方订单号
                    if (stringStringEntry.getKey().indexOf("订单编号") != -1 ||
                            stringStringEntry.getKey().indexOf("订单号") != -1 ||
                            stringStringEntry.getKey().indexOf("退票单号") != -1 ||
                            stringStringEntry.getKey().indexOf("子订单号/订单号") != -1 ||
                            stringStringEntry.getKey().indexOf("商户订单号") != -1){
                        if (!stringStringEntry.getValue().equals(" ")){
                            billDetailsVo.setOrderNum(stringStringEntry.getValue());
                        }
                    }

                    //获取单张票面价
                    if (stringStringEntry.getKey().indexOf("票面金额") != -1 ||
                            stringStringEntry.getKey().indexOf("票面金额(不含税)") != -1 ||
                            stringStringEntry.getKey().indexOf("票面价票面价差") != -1 ||
                            stringStringEntry.getKey().indexOf("票面价") != -1){
                        billDetailsVo.setFaceValue(stringStringEntry.getValue());
                    }

                    //获取手续费
                    if (stringStringEntry.getKey().indexOf("代理费") != -1 ||
                            stringStringEntry.getKey().indexOf("手续费") != -1 ||
                            stringStringEntry.getKey().indexOf("定额手续费") != -1){
                        billDetailsVo.setHandlingFee(stringStringEntry.getValue());
                    }

                    //获取单张票结算价
                    if (stringStringEntry.getKey().indexOf("实际支付金额") != -1 ||
                            stringStringEntry.getKey().indexOf("实际支付金额(含税)") != -1 ||
                            stringStringEntry.getKey().indexOf("实际支付") != -1 ||
                            stringStringEntry.getKey().indexOf("结算价") != -1 ||
                            stringStringEntry.getKey().indexOf("实付金额") != -1 ||
                            stringStringEntry.getKey().indexOf("票价总额") != -1 ||
                            stringStringEntry.getKey().indexOf("支付金额") != -1 ||
                            stringStringEntry.getKey().indexOf("Balance Payable") != -1 ||
                            stringStringEntry.getKey().indexOf("收入") != -1 ||
                            stringStringEntry.getKey().indexOf("支出") != -1){

                        if (stringStringEntry.getValue() != null && !stringStringEntry.getValue().equals("0")){
                            billDetailsVo.setSettlementPrice(stringStringEntry.getValue());
                        }
                    }

                    //燃油+基建
                    if (stringStringEntry.getKey().indexOf("燃油") != -1 ||
                            stringStringEntry.getKey().indexOf("燃油费") != -1){
                        fuel = stringStringEntry.getValue();
                    }

                    if (stringStringEntry.getKey().indexOf("机建") != -1 ||
                            stringStringEntry.getKey().indexOf("民航基金") != -1){
                        infrastructure = stringStringEntry.getValue();
                    }

                    //获取出票时间
                    if (stringStringEntry.getKey().indexOf("出票日期") != -1 ||
                            stringStringEntry.getKey().indexOf("出票时间") != -1 ||
                            stringStringEntry.getKey().indexOf("支付时间") != -1){
                        billDetailsVo.setTicketTime(stringStringEntry.getValue());
                    }

                    if (stringStringEntry.getKey().indexOf("交易日期") != -1){
                        tmpDate = stringStringEntry.getValue();
                    }
                    if (stringStringEntry.getKey().indexOf("交易时间") != -1){
                        time = stringStringEntry.getValue();
                    }

                    if (count == lstRowDatum.entrySet().size()){
                        if (fuel != null && infrastructure != null){
                            billDetailsVo.setFuelInfrastructure(fuel + "-" + infrastructure);
                        }
                        else if (fuel != null && infrastructure == null){
                            billDetailsVo.setFuelInfrastructure(fuel);
                        }
                        else if (fuel == null && infrastructure != null){
                            billDetailsVo.setFuelInfrastructure(infrastructure);
                        }

                        if (tmpDate != null && time != null){
                            billDetailsVo.setTicketTime(tmpDate + " " + time);
                        }

                        billDetailsVo.setUploadDate(dateFormat.format(financeAutobillRecord.getCreateTime()));
                        Employee employee = employeeService.selectEmployeeById(financeAutobillRecord.getEmployeeId());
                        billDetailsVo.setGenerator(employee.getEmployeeName());

                        Map<String, Object> map = new HashMap<>();
                        map.put("ticketNum", billDetailsVo.getRecordNum());
                        boolean flag = remoteFlightService.orderDetails(map);
                        if (flag){
                            billDetailsVo.setState("正常");
                        }
                        else {
                            billDetailsVo.setState("异常");
                        }

                        billDetailsVoList.add(billDetailsVo);
                        billDetailsVo = new BillDetailsVo();
                    }
                    else {
                        count = count + 1;
                    }
                }
            }

        } catch (Exception e){
            e.printStackTrace();
        }

        return billDetailsVoList;
    }

    /**
     * 对账
     * */
    @Transactional
    @Override
    public List<FinanceAutobillException> reconciliation(HttpServletRequest request, FinanceAutobillRecord financeAutobillRecord) throws Exception {
        String token = request.getHeader("token");
        Employee loginEmployeeByToken = loginService.getLoginEmployeeByToken(token);
        if (loginEmployeeByToken == null){
            throw new Exception("登录已过期");
        }

        int billCountInput = 0;//真实入账条数
        List<CountVo> countVoList = new ArrayList<>();
        Date dateTime = new Date();
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");

        financeAutobillRecord = financeAutobillRecordMapper.billDetails(financeAutobillRecord.getBillRecordId());

        String date = format.format(financeAutobillRecord.getCreateTime());

//        String downFilePath = "C:\\Users\\wangjing\\Desktop\\财务对账表\\6.2-6.5川航退票.xlsx";

//        String payFilePath = "C:\\Users\\wangjing\\Desktop\\财务对账表\\6.2-6.5汇付天下.xls";
//        List<String> lstPayColumns = new ArrayList<>();
//        lstPayColumns.add("PNR号");
//        lstPayColumns.add("支出");
//        lstPayColumns.add("收入");
//        List<Map<String, String>> lstPayRowData = ExcelUtils.readExcelWithColumn(payFilePath, lstPayColumns);

        String downFilePath = "D:\\ktgj\\reconciliation\\" + financeAutobillRecord.getNewName();
        String fileUrl = "http://172.16.7.51:9000/download/reconciliation/upload/" + date + "/" + financeAutobillRecord.getNewName();
        try {
            httpClientUtil.downloadNetworkFile(fileUrl, downFilePath);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            List<String> lstColumns = new ArrayList<>();
            lstColumns.add("AIR");
            lstColumns.add("Document Number");//票号
            lstColumns.add("Balance Payable");//金额
            lstColumns.add("电子客票票号");
            lstColumns.add("应退金额");
            lstColumns.add("起始票号");
            lstColumns.add("支付金额");
            lstColumns.add("收入");
            lstColumns.add("支出");
            lstColumns.add("票号");
            lstColumns.add("实际支付金额(含税)");
            lstColumns.add("票价总额");
            lstColumns.add("实付金额");
            lstColumns.add("退票单号");
            lstColumns.add("退款金额");
            lstColumns.add("实际支付");
            lstColumns.add("实际退票金额");
            lstColumns.add("支付银行");
            lstColumns.add("商户名");
            lstColumns.add("支付方式");
            lstColumns.add("收款方名称");
            lstColumns.add("订单编号");
            lstColumns.add("银行订单号");
            lstColumns.add("订单号");
            lstColumns.add("子订单号/订单号/变更单号");
            lstColumns.add("子订单号/订单号");
            lstColumns.add("商户订单号");
            lstColumns.add("税");
            lstColumns.add("税总");
            lstColumns.add("代理费");
            lstColumns.add("TaxCash");
            lstColumns.add("Taxes");
            lstColumns.add("OtherTaxCash");
            List<Map<String, String>> lstRowData = ExcelUtils.readExcelWithColumn(downFilePath, lstColumns);
            Map<String, String> mRefundRow = lstRowData.get(0);
            if (mRefundRow.get("AIR")!=null && mRefundRow.get("AIR").equals("*** REFUNDS"))
            {
                int pos = 0;
                for (Map<String, String> mRow : lstRowData)
                {
                    if (pos == lstRowData.size() - 1)
                    {
                        continue;
                    }
                    if (pos % 1 == 0)
                    {
                        String tmpTicket = lstRowData.get(pos + 1).get("Document Number");
                        mRow.replace("Document Number", mRow.get("AIR") + tmpTicket);
                    }
                    pos++;
                }
                for (int i = lstRowData.size() - 1; i >= 0; i--)
                {
                    Map<String, String> mData = lstRowData.get(i);
                    if (StringHelper.isNullOrEmpty(mData.get("Balance Payable")) || mData.get("Balance Payable") == null)
                    {
                        lstRowData.remove(i);
                    }
                }
            }
            String air = null;
            CountVo countVo = new CountVo();
            for (Map<String, String> rowData : lstRowData)
            {
                if (rowData.get("Balance Payable")!=null && rowData.get("Balance Payable").indexOf("-") != -1)
                {
                    countVo.airline = "CA";
                    countVo.ticketingChannel = "航协";
                    countVo.type = "refund";
                }
                if (rowData.get("Balance Payable")!=null && rowData.get("Balance Payable").indexOf("-") == -1)
                {
                    countVo.airline = "CA";
                    countVo.ticketingChannel = "航协";
                    countVo.type = "pay";
                }
                if (StringHelper.isNullOrEmpty(rowData.get("TaxCash")) && !StringHelper.isNullOrEmpty(rowData.get("Taxes")))
                {
                    rowData.replace("TaxCash", "0");
                }
                for (Map.Entry<String, String> rowEntry : rowData.entrySet())
                {
                    if (!StringHelper.isNullOrEmpty(rowData.get("AIR")))
                    {
                        air = rowData.get("AIR");
                    }
                    //获取出票渠道
                    if (rowEntry.getKey().indexOf("支付银行") != -1 ||
                            rowEntry.getKey().indexOf("商户名") != -1 ||
                            rowEntry.getKey().indexOf("支付方式") != -1 ||
                            rowEntry.getKey().indexOf("收款方名称") != -1)
                    {
                        if (rowEntry.getValue() != null)
                        {
                            countVo.ticketingChannel = rowEntry.getValue();
                        }
                    }
                    //外部单号
                    if (rowEntry.getKey().indexOf("订单编号") != -1 ||
                            rowEntry.getKey().indexOf("银行订单号") != -1 ||
                            rowEntry.getKey().indexOf("订单号") != -1 ||
                            rowEntry.getKey().indexOf("子订单号/订单号/变更单号") != -1 ||
                            rowEntry.getKey().indexOf("子订单号/订单号") != -1 ||
                            rowEntry.getKey().indexOf("商户订单号") != -1)
                    {
                        countVo.orderNum = rowEntry.getValue();
                    }
                    //获取票号
                    if (rowEntry.getKey().indexOf("Document Number") != -1 ||
                            rowEntry.getKey().indexOf("电子客票票号") != -1 ||
                            rowEntry.getKey().indexOf("起始票号") != -1 ||
                            rowEntry.getKey().indexOf("票号") != -1 ||
                            rowEntry.getKey().indexOf("退票单号") != -1)
                    {
                        if (air != null)
                        {
                            countVo.ticketNumber = air + "-" + rowEntry.getValue();
                        } else
                        {
                            countVo.ticketNumber = rowEntry.getValue();
                        }
                    }
                    //获取退款金额
                    if (rowEntry.getKey().indexOf("应退金额") != -1 ||
                            rowEntry.getKey().indexOf("支出") != -1 ||
                            rowEntry.getKey().indexOf("退款金额") != -1 ||
                            rowEntry.getKey().indexOf("实际退票金额") != -1)
                    {
                        if (!rowEntry.getValue().equals("0"))
                        {
                            countVo.amount = rowEntry.getValue();
                            countVo.type = "refund";
                        }
                    }
                    if (rowEntry.getKey().indexOf("PNR")!=-1 || rowEntry.getKey().indexOf("BPNR")!=-1 || rowEntry.getKey().indexOf("")!=-1)
                    {
                        countVo.pnr = rowEntry.getValue();
                    }
                    //获取支付金额
                    else if (rowEntry.getKey().indexOf("支付金额") != -1 ||
                            rowEntry.getKey().indexOf("收入") != -1 ||
                            rowEntry.getKey().indexOf("实际支付金额(含税)") != -1 ||
                            rowEntry.getKey().indexOf("票价总额") != -1 ||
                            rowEntry.getKey().indexOf("实付金额") != -1 ||
                            rowEntry.getKey().indexOf("实际支付") != -1)
                    {
                        if (!rowEntry.getValue().equals("0"))
                        {
                            countVo.amount = rowEntry.getValue();
                            countVo.type = "pay";
                        }
                    } else if (rowEntry.getKey().indexOf("税总") != -1 || rowEntry.getKey().indexOf("税") != -1)
                    {
                        countVo.taxAmount = rowEntry.getValue();
                    } else if (rowEntry.getKey().indexOf("代理费") != -1)
                    {
                        countVo.commission = rowEntry.getValue();
                    } else if (!StringHelper.isNullOrEmpty(rowData.get("TaxCash")) && !StringHelper.isNullOrEmpty(rowData.get("Taxes")))
                    {
                        String taxes = rowData.get("Taxes");
                        countVo.taxAmount = String.valueOf(Long.valueOf(rowData.get("TaxCash")) + Long.valueOf(rowData.get("Taxes").substring(0, taxes.indexOf(".00  YQ"))));
                    } else if (StringHelper.isNullOrEmpty(rowData.get("TaxCash")) && StringHelper.isNullOrEmpty(rowData.get("Taxes")))
                    {
                        countVo.taxAmount = "0";
                    } else if (!StringHelper.isNullOrEmpty("TaxCash") && !StringHelper.isNullOrEmpty(rowData.get("OtherTaxCash")))
                    {
                        if (rowData.get("OtherTaxCash").indexOf("  YQ") != -1)
                        {
                            countVo.taxAmount = String.valueOf(Long.valueOf(rowData.get("TaxCash").substring(0, rowData.get("TaxCash").indexOf(".00  CN"))) + Long.valueOf(rowData.get("OtherTaxCash").substring(0, rowData.get("OtherTaxCash").indexOf(".00  YQ"))));
                        }
                    } else if (!StringHelper.isNullOrEmpty(rowData.get("TaxCash")) && StringHelper.isNullOrEmpty(rowData.get("OtherTaxCash")))
                    {
                        countVo.taxAmount = String.valueOf(Long.valueOf(rowData.get("TaxCash")) + Long.valueOf(rowData.get("Taxes").substring(0, rowData.get("Taxes").indexOf(".00  YQ"))));
                    }
                    if (financeAutobillRecord.getReportType().equals(FlightOrderConstants.Sales.getValue()) &&
                            rowEntry.getKey().equals("Balance Payable"))
                    {
                        if (!rowEntry.getValue().equals("0"))
                        {
                            countVo.amount = rowEntry.getValue();
                            countVo.type = "pay";
                        }
                    }
                    if (financeAutobillRecord.getReportType().equals(FlightOrderConstants.Refund.getValue()) &&
                            rowEntry.getKey().equals("Balance Payable"))
                    {
                        if (!rowEntry.getValue().equals("0"))
                        {
                            countVo.amount = rowEntry.getValue();
                            countVo.type = "refund";
                        }
                    }

                    if (financeAutobillRecord.getExceltype().equals(FlightOrderConstants.Airline.getValue()))
                    {
                        countVo.airline = financeAutobillRecord.getBillBelong();
                    }

                    if (countVo.amount != null && countVo.type != null && countVo.ticketingChannel != null)
                    {
                        countVoList.add(countVo);
                        countVo = new CountVo();
                    }
                }
            }


            String airline = financeAutobillRecord.getBillBelong().substring(financeAutobillRecord.getBillBelong().length() - 2);
            int indexOf = financeAutobillRecord.getBillTimeNumber().indexOf("-");
            String start = financeAutobillRecord.getBillTimeNumber().substring(0, indexOf);
            start = start.substring(0, 4) + "-" + start.substring(4, 6) + "-" + start.substring(6);
            String end = financeAutobillRecord.getBillTimeNumber().substring(indexOf + 1);
            end = end.substring(0, 4) + "-" + end.substring(4, 6) + "-" + end.substring(6);
            Map<String, Object> map = new HashMap<>();
            map.put("airline", airline);
            map.put("start", start);
            map.put("end", end);
            //获取退票订单列表
            List<FlightOrderChange> flightOrderChanges = remoteFlightService.refundList(map);
            //获取支付订单列表
            List<FlightOrderInfo> flightOrderInfos = remoteFlightService.payList(map);
            //删除原对账数据直接对账
            financeAutobillExceptionMapper.deleteFinanceAutobillExceptionById(financeAutobillRecord.getBillRecordId());
            //对账
            int count = 0;//缺失标识(0没有 1有)
            int amount = 0;//金额不同标识(1相同 0不同)
            int tmpAmounts = 0;//(2少收 3多收)
            for (CountVo vo : countVoList)
            {
                //销售
                if (vo.type.equals("pay"))
                {
                    if (flightOrderInfos.size() > 0)
                    {
                        for (FlightOrderInfo flightOrderInfo : flightOrderInfos)
                        {
                            for (FlightOrderInfoTickets flightOrderInfoTicketsApi : flightOrderInfo.getInfoTickets())
                            {
                                String ticketNumberVo = vo.ticketNumber.replace("-", "");
                                String ticketNumber = flightOrderInfoTicketsApi.getTicketNo().replace("-", "");
                                if (ticketNumberVo.equals(ticketNumber))
                                {
                                    count = 1;
                                    if (flightOrderInfoTicketsApi.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == 0)
                                    {
                                        amount = 1;
                                        billCountInput = billCountInput + 1;
                                    }
                                    if (flightOrderInfoTicketsApi.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == -1)
                                    {
                                        tmpAmounts = 2;//少收
                                    } else if (flightOrderInfoTicketsApi.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == 1)
                                    {
                                        tmpAmounts = 3;//多收
                                    }
                                }
                            }
                        }
                    }

                    //航司有，crm没有
                    FinanceAutobillException financeAutobillException = new FinanceAutobillException();
//                        financeAutobillException.setSummaryBillId();
                    if (count == 0)
                    {
                        financeAutobillException.setExceptionType(FlightOrderConstants.CrmLess.getValue());
                    } else if (count == 1)
                    {
                        if (amount == 1)
                        {
                            financeAutobillException.setExceptionType(FlightOrderConstants.Normal.getValue());
                        } else if (amount == 0)
                        {
                            if (tmpAmounts == 2)
                            {
                                financeAutobillException.setExceptionType(FlightOrderConstants.BuyMoneyLess.getValue());
                            } else if (tmpAmounts == 3)
                            {
                                financeAutobillException.setExceptionType(FlightOrderConstants.BuyMoneyMore.getValue());
                            }
                        }
                    }
                    count = 0;
                    amount = 0;
                    tmpAmounts = 0;
                    financeAutobillException.setStatus("2");
                    financeAutobillException.setSummaryBillId(financeAutobillRecord.getBillRecordId());
                    financeAutobillException.setOperationtime(dateTime);
                    financeAutobillException.setOperator(loginEmployeeByToken.getEmployeeId());
//                        financeAutobillException.setPayableId();
                    financeAutobillException.setCheckTimes(1l);
                    financeAutobillException.setCreateTime(dateTime);
                    financeAutobillException.setOutsideBillNumber(vo.orderNum);
                    financeAutobillException.setTicketNumber(vo.ticketNumber);
                    financeAutobillException.setTicketingChannel(vo.ticketingChannel);
                    financeAutobillException.setAmount(new BigDecimal(vo.amount));
                    if (vo.taxAmount == null || vo.taxAmount == "")
                    {
                        financeAutobillException.setTaxAmount(new BigDecimal(0));
                    } else
                    {
                        financeAutobillException.setTaxAmount(new BigDecimal(vo.taxAmount));
                    }
                    if (vo.commission == null || vo.commission == "")
                    {
                        financeAutobillException.setCommission(new BigDecimal(0));
                    } else
                    {
                        financeAutobillException.setCommission(new BigDecimal(vo.commission));
                    }
                    financeAutobillException.setBillTimeNumber(financeAutobillRecord.getBillTimeNumber());
                    int i = financeAutobillExceptionMapper.insertFinanceAutobillException(financeAutobillException);
                    if (i <= 0)
                    {
                        throw new Exception("添加失败" + vo.ticketNumber);
                    }
                }
                //退票
                else if (vo.type.equals("refund"))
                {
                    for (FlightOrderChange flightOrderChange : flightOrderChanges)
                    {
                        for (FlightOrderChangeTickets flightOrderChangeTickets : flightOrderChange.getChangeTicketsList())
                        {
                            String ticketNumberVo = vo.ticketNumber.replace("-", "");
                            String ticketNumber = flightOrderChangeTickets.getTicketNo().replace("-", "");
                            if (ticketNumberVo.equals(ticketNumber))
                            {
                                count = 1;
                                if (flightOrderChangeTickets.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == 0)
                                {
                                    amount = 1;
                                    billCountInput = billCountInput + 1;
                                }
                                if (flightOrderChangeTickets.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == -1)
                                {
                                    tmpAmounts = 2;//少收
                                } else if (flightOrderChangeTickets.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == 1)
                                {
                                    tmpAmounts = 3;//多收
                                }
                            }
                        }
                    }

                    //航司有，crm没有
                    FinanceAutobillException financeAutobillException = new FinanceAutobillException();
//                        financeAutobillException.setSummaryBillId();
                    if (count == 0)
                    {
                        financeAutobillException.setExceptionType(FlightOrderConstants.CrmLess.getValue());
                    } else if (count == 1)
                    {
                        if (amount == 1)
                        {
                            financeAutobillException.setExceptionType(FlightOrderConstants.Normal.getValue());
                        } else if (amount == 0)
                        {
                            if (tmpAmounts == 2)
                            {
                                financeAutobillException.setExceptionType(FlightOrderConstants.ReturnMoneyLess.getValue());
                            } else if (tmpAmounts == 3)
                            {
                                financeAutobillException.setExceptionType(FlightOrderConstants.ReturnMoneyMore.getValue());
                            }
                        }
                    }
                    count = 0;
                    amount = 0;
                    tmpAmounts = 0;
                    financeAutobillException.setStatus("2");
                    financeAutobillException.setSummaryBillId(financeAutobillRecord.getBillRecordId());
                    financeAutobillException.setOperationtime(dateTime);
                    financeAutobillException.setCreateTime(dateTime);
                    financeAutobillException.setOperator(loginEmployeeByToken.getEmployeeId());
//                        financeAutobillException.setPayableId();
                    financeAutobillException.setCheckTimes(1l);
                    financeAutobillException.setOutsideBillNumber(vo.orderNum);
                    financeAutobillException.setTicketNumber(vo.ticketNumber);
                    financeAutobillException.setTicketingChannel(vo.ticketingChannel);
                    financeAutobillException.setAmount(new BigDecimal(vo.amount));
                    if (vo.taxAmount == null || vo.taxAmount == "")
                    {
                        financeAutobillException.setTaxAmount(new BigDecimal(0));
                    } else
                    {
                        financeAutobillException.setTaxAmount(new BigDecimal(vo.taxAmount));
                    }
                    if (vo.commission == null || vo.commission == "")
                    {
                        financeAutobillException.setCommission(new BigDecimal(0));
                    } else
                    {
                        financeAutobillException.setCommission(new BigDecimal(vo.commission));
                    }
                    financeAutobillException.setBillTimeNumber(financeAutobillRecord.getBillTimeNumber());
                    int i = financeAutobillExceptionMapper.insertFinanceAutobillException(financeAutobillException);
                    if (i <= 0)
                    {
                        throw new Exception("添加失败" + vo.ticketNumber);
                    }
                }
            }

//            //二次对账(退款)
//            int tmpCount = 0;
//            int tmpAmount = 0;
//            int mount = 0;
//            int refund = 0;//是否有退款数据
//            String orderNum = null;
//            if (flightOrderInfoTicketsApis != null && flightOrderInfoTicketsApis.size() > 0){
//                for (FlightOrderInfoTicketsApi flightOrderInfoTicketsApi : flightOrderInfoTicketsApis) {
//                    for (CountVo vo : countVoList) {
//                        //退款
//
//
//                        if (vo.type.equals("refund")){
//                            refund = 1;
//                            orderNum = vo.orderNum;
//                            String ticketNumberVo = vo.ticketNumber.replace("-", "");
//                            String ticketNumber = flightOrderInfoTicketsApi.getTicketNo().replace("-", "");
//                            if (ticketNumberVo.equals(ticketNumber)){
//                                tmpCount = 1;
//                                if (flightOrderInfoTicketsApi.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == 0){
//                                    tmpAmount = 1;
//                                }
//                                if (flightOrderInfoTicketsApi.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == -1){
//                                    mount = 2;//少收
//                                }
//                                else if (flightOrderInfoTicketsApi.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == 1){
//                                    mount = 3;//多收
//                                }
//                            }
//                        }
//                    }
//
//                    if (refund == 1){
//                        refund = 0;
//                        FinanceAutobillException TmpFinanceAutobillException = financeAutobillExceptionMapper.financeAutobillException(flightOrderInfoTicketsApi.getTicketNo());
//                        if (TmpFinanceAutobillException == null){
//                            FinanceAutobillException financeAutobillException = new FinanceAutobillException();
////                        financeAutobillException.setSummaryBillId();
//                            if (tmpCount == 0){
//                                financeAutobillException.setExceptionType(FlightOrderConstants.CrmMore.getValue());
//                            }
//                            else if (tmpCount == 1){
//                                if (tmpAmount == 1){
//                                    financeAutobillException.setExceptionType(FlightOrderConstants.Normal.getValue());
//                                }
//                                else if (tmpAmount == 0){
//                                    if (mount == 2){
//                                        financeAutobillException.setExceptionType(FlightOrderConstants.ReturnMoneyLess.getValue());
//                                    }
//                                    else if (mount == 3){
//                                        financeAutobillException.setExceptionType(FlightOrderConstants.ReturnMoneyMore.getValue());
//                                    }
//                                }
//                            }
//                            tmpCount = 0;
//                            tmpAmount = 0;
//                            mount = 0;
//                            financeAutobillException.setExceptionType(FlightOrderConstants.CrmMore.getValue());
//                            financeAutobillException.setStatus("2");
//                            financeAutobillException.setOperationtime(dateTime);
//                            financeAutobillException.setCreateTime(dateTime);
//                            financeAutobillException.setOperator(loginEmployeeByToken.getEmployeeId());
////                        financeAutobillException.setPayableId();
//                            financeAutobillException.setCheckTimes(1l);
//                            financeAutobillException.setOutsideBillNumber(orderNum);
//                            financeAutobillException.setFlightOrderInfoTicketsId(flightOrderInfoTicketsApi.getOrderInfoTicketsId());
//                            financeAutobillException.setTicketNumber(flightOrderInfoTicketsApi.getTicketNo());
//                            Map<String, Long> order = new HashMap<>();
//                            order.put("orderId", flightOrderInfoTicketsApi.getOrderId());
//                            R<FlightOrderInfo> info = remoteFlightService.getInfo(order);
//                            if (info.getData() != null){
//                                if (info.getData().getPayType() != null){
//                                    if (info.getData().getPayType().equals(CustomerConstants.cash.getValue())){
//                                        financeAutobillException.setTicketingChannel("现金");
//                                    }
//                                    else if (info.getData().getPayType().equals("wechatPay")){
//                                        financeAutobillException.setTicketingChannel("微信支付");
//                                    }
//                                    else if (info.getData().getPayType().equals("unionPay")){
//                                        financeAutobillException.setTicketingChannel("银联");
//                                    }
//                                    else if (info.getData().getPayType().equals("UnionPayQRCode")){
//                                        financeAutobillException.setTicketingChannel("银联二维码");
//                                    }
//                                    else if (info.getData().getPayType().equals(EmHelper.cardType.WeChat.getValue())){
//                                        financeAutobillException.setTicketingChannel("微信");
//                                    }
//                                    else if (info.getData().getPayType().equals(EmHelper.cardType.BankCardPay.getValue())){
//                                        financeAutobillException.setTicketingChannel("银行卡支付");
//                                    }
//                                    else if (info.getData().getPayType().equals(EmHelper.cardType.DEBIT_CARD.getValue())){
//                                        financeAutobillException.setTicketingChannel("借记卡");
//                                    }
//                                    else if (info.getData().getPayType().equals("BankDebit")){
//                                        financeAutobillException.setTicketingChannel("借记卡");
//                                    }
//                                }
//                            }
//                            financeAutobillException.setBillTimeNumber(financeAutobillRecord.getBillTimeNumber());
//                            int i = financeAutobillExceptionMapper.insertFinanceAutobillException(financeAutobillException);
//                            orderNum = null;
//                            if (i <= 0){
//                                throw new Exception("添加失败" + flightOrderInfoTicketsApi.getTicketNo());
//                            }
//                        }
//                        else {
//                            tmpCount = 0;
//                            tmpAmount = 0;
//                            mount = 0;
//                        }
//                    }
//                }
//            }
//            else {
//                //crm没有航司有
//                for (CountVo vo : countVoList) {
//                    if (vo.type.equals("refund")){
//                        FinanceAutobillException financeAutobillException = new FinanceAutobillException();
////                        financeAutobillException.setSummaryBillId();
//                        financeAutobillException.setExceptionType(FlightOrderConstants.CrmLess.getValue());
//                        tmpCount = 0;
//                        tmpAmount = 0;
//                        mount = 0;
//                        financeAutobillException.setStatus("2");
//                        financeAutobillException.setOperationtime(dateTime);
//                        financeAutobillException.setCreateTime(dateTime);
//                        financeAutobillException.setOperator(loginEmployeeByToken.getEmployeeId());
////                        financeAutobillException.setPayableId();
//                        financeAutobillException.setCheckTimes(1l);
//                        financeAutobillException.setOutsideBillNumber(orderNum);
//                        financeAutobillException.setTicketNumber(vo.ticketNumber);
//                        financeAutobillException.setBillTimeNumber(financeAutobillRecord.getBillTimeNumber());
//                        int i = financeAutobillExceptionMapper.insertFinanceAutobillException(financeAutobillException);
//                        orderNum = null;
//                        if (i <= 0){
//                            throw new Exception("添加失败,数据库没有对应数据");
//                        }
//                    }
//                }
//            }
//
//            //二次对账(销售)
//            if (flightOrderInfoTicketsApiList != null && flightOrderInfoTicketsApiList.size() > 0){
//                for (FlightOrderInfoTicketsApi flightOrderInfoTicketsApi : flightOrderInfoTicketsApiList) {
//                    for (CountVo vo : countVoList) {
//                        //销售
//                        if (vo.type.equals("pay")){
//                            refund = 1;
//                            orderNum = vo.orderNum;
//                            String ticketNumberVo = vo.ticketNumber.replace("-", "");
//                            String ticketNumber = flightOrderInfoTicketsApi.getTicketNo().replace("-", "");
//                            if (ticketNumberVo.equals(ticketNumber)){
//                                tmpCount = 1;
//                                if (flightOrderInfoTicketsApi.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == 0){
//                                    tmpAmount = 1;
//                                }
//                                if (flightOrderInfoTicketsApi.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == -1){
//                                    mount = 2;//少收
//                                }
//                                else if (flightOrderInfoTicketsApi.getTicketPrice().compareTo(new BigDecimal(vo.amount)) == 1){
//                                    mount = 3;//多收
//                                }
//                            }
//                        }
//                    }
//
//                    //crm有，航司没有
//                    if (refund == 1){
//                        refund = 0;
//
//                        FinanceAutobillException TmpFinanceAutobillException = financeAutobillExceptionMapper.financeAutobillException(flightOrderInfoTicketsApi.getTicketNo());
//                        if (TmpFinanceAutobillException == null){
//                            FinanceAutobillException financeAutobillException = new FinanceAutobillException();
////                        financeAutobillException.setSummaryBillId();
//                            if (tmpCount == 0){
//                                financeAutobillException.setExceptionType(FlightOrderConstants.CrmMore.getValue());
//                            }
//                            else if (tmpCount == 1){
//                                if (tmpAmount == 1){
//                                    financeAutobillException.setExceptionType(FlightOrderConstants.Normal.getValue());
//                                }
//                                else if (tmpAmount == 0){
//                                    if (mount == 2){
//                                        financeAutobillException.setExceptionType(FlightOrderConstants.BuyMoneyLess.getValue());
//                                    }
//                                    else if (mount == 3){
//                                        financeAutobillException.setExceptionType(FlightOrderConstants.BuyMoneyMore.getValue());
//                                    }
//                                }
//                            }
//                            tmpCount = 0;
//                            tmpAmount = 0;
//                            mount = 0;
//                            financeAutobillException.setStatus("2");
//                            financeAutobillException.setOperationtime(dateTime);
//                            financeAutobillException.setCreateTime(dateTime);
//                            financeAutobillException.setOperator(loginEmployeeByToken.getEmployeeId());
////                        financeAutobillException.setPayableId();
//                            financeAutobillException.setCheckTimes(1l);
//                            financeAutobillException.setOutsideBillNumber(orderNum);
//                            financeAutobillException.setFlightOrderInfoTicketsId(flightOrderInfoTicketsApi.getOrderInfoTicketsId());
//                            financeAutobillException.setTicketNumber(flightOrderInfoTicketsApi.getTicketNo());
//                            Map<String, Long> order = new HashMap<>();
//                            order.put("orderId", flightOrderInfoTicketsApi.getOrderId());
//                            R<FlightOrderInfo> info = remoteFlightService.getInfo(order);
//                            if (info.getData() != null){
//                                if (info.getData().getPayType() != null){
//                                    if (info.getData().getPayType().equals(CustomerConstants.cash.getValue())){
//                                        financeAutobillException.setTicketingChannel("现金");
//                                    }
//                                    else if (info.getData().getPayType().equals("wechatPay")){
//                                        financeAutobillException.setTicketingChannel("微信支付");
//                                    }
//                                    else if (info.getData().getPayType().equals("unionPay")){
//                                        financeAutobillException.setTicketingChannel("银联");
//                                    }
//                                    else if (info.getData().getPayType().equals("UnionPayQRCode")){
//                                        financeAutobillException.setTicketingChannel("银联二维码");
//                                    }
//                                    else if (info.getData().getPayType().equals(EmHelper.cardType.WeChat.getValue())){
//                                        financeAutobillException.setTicketingChannel("微信");
//                                    }
//                                    else if (info.getData().getPayType().equals(EmHelper.cardType.BankCardPay.getValue())){
//                                        financeAutobillException.setTicketingChannel("银行卡支付");
//                                    }
//                                    else if (info.getData().getPayType().equals(EmHelper.cardType.DEBIT_CARD.getValue())){
//                                        financeAutobillException.setTicketingChannel("借记卡");
//                                    }
//                                    else if (info.getData().getPayType().equals("BankDebit")){
//                                        financeAutobillException.setTicketingChannel("借记卡");
//                                    }
//                                }
//                            }
//                            financeAutobillException.setBillTimeNumber(financeAutobillRecord.getBillTimeNumber());
//                            int i = financeAutobillExceptionMapper.insertFinanceAutobillException(financeAutobillException);
//                            orderNum = null;
//                            if (i <= 0){
//                                throw new Exception("添加失败" + flightOrderInfoTicketsApi.getTicketNo());
//                            }
//                        }
//                        else {
//                            tmpCount = 0;
//                            tmpAmount = 0;
//                            mount = 0;
//                        }
//                    }
//                }
//            }
//            else {
//                //crm没有航司有
//                for (CountVo vo : countVoList) {
//                    if (vo.type.equals("pay")){
//                        FinanceAutobillException financeAutobillException = new FinanceAutobillException();
////                        financeAutobillException.setSummaryBillId();
//                        financeAutobillException.setExceptionType(FlightOrderConstants.CrmLess.getValue());
//                        tmpCount = 0;
//                        tmpAmount = 0;
//                        mount = 0;
//                        financeAutobillException.setExceptionType(FlightOrderConstants.CrmMore.getValue());
//                        financeAutobillException.setStatus("2");
//                        financeAutobillException.setOperationtime(dateTime);
//                        financeAutobillException.setCreateTime(dateTime);
//                        financeAutobillException.setOperator(loginEmployeeByToken.getEmployeeId());
////                        financeAutobillException.setPayableId();
//                        financeAutobillException.setCheckTimes(1l);
//                        financeAutobillException.setOutsideBillNumber(orderNum);
//                        financeAutobillException.setTicketNumber(vo.ticketNumber);
//                        financeAutobillException.setAmount(new BigDecimal(Long.valueOf(vo.amount)));
//                        financeAutobillException.setTaxAmount(new BigDecimal(vo.taxAmount==null?0l:Long.valueOf(vo.taxAmount)));
//                        financeAutobillException.setCommission(new BigDecimal(vo.commission==null?0l:Long.valueOf(vo.commission)));
//                        financeAutobillException.setBillTimeNumber(financeAutobillRecord.getBillTimeNumber());
//                        int i = financeAutobillExceptionMapper.insertFinanceAutobillException(financeAutobillException);
//                        orderNum = null;
//                        if (i <= 0){
//                            throw new Exception("添加失败,数据库没有对应数据");
//                        }
//                    }
//                }
//            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        List<FinanceAutobillException> financeAutobillExceptions = financeAutobillExceptionMapper.financeAutobillExceptionList();
        for (FinanceAutobillException financeAutobillException : financeAutobillExceptions) {
            if (financeAutobillException.getOperator() != null){
                Employee employee = employeeService.selectEmployeeById(financeAutobillException.getOperator());
                if (employee != null){
                    financeAutobillException.setOperatorName(employee.getEmployeeName());
                }
            }
            if (financeAutobillException.getExceptionType().equals(FlightOrderConstants.ReturnMoneyLess.getValue())){
                financeAutobillException.setExceptionType("少收客人退票费");
            }
            else if (financeAutobillException.getExceptionType().equals(FlightOrderConstants.ReturnMoneyMore.getValue())){
                financeAutobillException.setExceptionType("多收客人退票费");
            }
            else if (financeAutobillException.getExceptionType().equals(FlightOrderConstants.CrmLess.getValue())){
                financeAutobillException.setExceptionType("CRM没有对方有");
            }
            else if (financeAutobillException.getExceptionType().equals(FlightOrderConstants.CrmMore.getValue())){
                financeAutobillException.setExceptionType("CRM有对方没有");
            }
            else if (financeAutobillException.getExceptionType().equals(FlightOrderConstants.BuyMoneyLess.getValue())){
                financeAutobillException.setExceptionType("少收客人票价");
            }
            else if (financeAutobillException.getExceptionType().equals(FlightOrderConstants.BuyMoneyMore.getValue())){
                financeAutobillException.setExceptionType("多收客人票价");
            }
        }

        financeAutobillRecord.setBillCount(Long.valueOf(countVoList.size() - 1));
        financeAutobillRecord.setBillCountInput(Long.valueOf(billCountInput));
        int i = financeAutobillRecordMapper.updateBillCountInput(financeAutobillRecord);
        if (i > 0){
            return financeAutobillExceptions;
        }
        else {
            throw new Exception("修改真实入账条数失败");
        }
    }
}
